package com.csun.cmny;

import cn.jpush.api.JPushClient;
import com.csun.cmny.config.properties.CmnyProperties;
import com.csun.cmny.provider.resolver.CmnyLocaleResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;
import tk.mybatis.spring.annotation.MapperScan;

import javax.annotation.Resource;
import javax.validation.Validator;
import java.util.Locale;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2018-11-29 11:50
 * @Description:
 */
@Slf4j
@EnableHystrix
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
@MapperScan("com.csun.cmny.provider.dao")
@EnableScheduling
public class CmnyProviderOmcApplication {

    @Resource
    private CmnyProperties cmnyProperties;

    public static void main(String[] args) {
        SpringApplication.run(com.csun.cmny.CmnyProviderOmcApplication.class, args);
        System.out.println("start cmny-provider-omc success!");
    }

    @Bean
    public LocaleResolver localeResolver() {
        return new CmnyLocaleResolver();
    }

    @Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        Locale.setDefault(Locale.CHINA);
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setDefaultEncoding("UTF-8");
        messageSource.setBasenames("i18n/errors/ErrorMessages", "i18n/prompt/PromptMessages",
                "i18n/validation/ValidationMessages", "classpath:ValidationMessages",
                "classpath:ErrorCodeMessages");
        return messageSource;
    }

    @Bean
    public Validator getValidator() throws Exception {
        LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
        validator.setValidationMessageSource(messageSource());
        return validator;
    }

    @Bean
    public CmnyLocaleResolver cmnyLocaleResolver() {
        return new CmnyLocaleResolver();
    }

    /**
     * 社区版-中控台
     */
    @Bean(name = "cmnyVolunteer")
    public JPushClient getCmnyVolunteer() {
        JPushClient jPushClient = new JPushClient(cmnyProperties.getJpush().getCmnyVolunteer().getMasterSecret(),
                cmnyProperties.getJpush().getCmnyVolunteer().getAppKey());
        return jPushClient;
    }

    /*极光推送 -- 医生app*/
    @Bean(name = "shouhjDoctor")
    public JPushClient getShouhjDoctor() {

        return new JPushClient("6165fe7c900182e51e4a683c", "2e55d2094d9c4a4bc5f98be1");
    }

    /*极光推送 -- 华隆医生app*/
    @Bean(name = "shjhlDoctor")
    public JPushClient shjhlDoctor() {

        return new JPushClient("af311e7fc055192fe8b12134", "bb19687a22d2e0e6df8cb9e7");
    }

    /*极光推送 -- 华隆护工app*/
    @Bean(name = "shjhlNursing")
    public JPushClient shjhlNursing() {

        return new JPushClient("e9c4fbf432d3e4722fd2046b", "b62ffdfbd5e2cdb9006a4b2a");
    }
    /**
     * 极光推送 -- 守护佳-社区版-家属App
     */
    @Bean(name = "shouhjFamily")
    public JPushClient getShouhjFamily() {
//        JPushClient jPushClient = new JPushClient(cmnyProperties.getJpush().getCmnyFamily().getMasterSecret(),
//                cmnyProperties.getJpush().getCmnyFamily().getAppKey());

        return new JPushClient("09627f5947f50c3457b28998", "481e2d18ed9d36bfab31670c");
    }
}
